﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Benefit.ViewModel.Month
{
    public class GroupMonthCompare
    {
        /// <summary>
        /// 左侧菜单显示信息
        /// </summary>
        public LeftMenuInfos LeftMenuInfos { get; set; }

        public string GroupQueryDate { get; set; }

        public Models.Sys.Groups Group { get; set; }

        public string QueryMonth { get; set; }

        public string QueryYear { get; set; }

        public string Pdate { get; set; }

        public string GroupId { get; set; }

        public string QueryDate { get; set; }

        public List<Models.Month.GroupMonthWinOrLoseTick> WinGroupMonthWinOrLoseTick { get; set; }

        public List<Models.Month.GroupMonthWinOrLoseTick> LostGroupMonthWinOrLoseTick { get; set; }

        public string JS { get; set; }

        #region 定义一些使用到的接口
        private Interface.Sys.IGroups IGroups = null;
        private Interface.Sys.ITradeHistory ITradeHistory = null;
        private Interface.Month.IGroupMonthWinOrLoseTick IGroupMonthWinOrLoseTick = null;
        private Interface.Day.IGroupDayChange IGroupDayChange = null;
        #endregion


        public GroupMonthCompare(int groupId, int queryDate, DB.DBManager db)
        {
            InitInterface(db);
            this.Group = IGroups.GetGroup(groupId);
            this.GroupQueryDate = queryDate.ToString();
            this.QueryMonth = queryDate.ToString().Substring(4, 2);
            this.QueryYear = queryDate.ToString().Substring(0, 4);
            this.WinGroupMonthWinOrLoseTick = IGroupMonthWinOrLoseTick.GetSortedGroupMonthWinOrLoseTick(groupId, Convert.ToInt32(this.QueryMonth), Convert.ToInt32(this.QueryYear), true);
            this.LostGroupMonthWinOrLoseTick = IGroupMonthWinOrLoseTick.GetSortedGroupMonthWinOrLoseTick(groupId, Convert.ToInt32(this.QueryMonth), Convert.ToInt32(this.QueryYear), false);

            List<Models.Day.GroupDayChange> groupDayChanges = IGroupDayChange.GetGroupDayChange(groupId, Convert.ToInt32(this.QueryMonth), Convert.ToInt32(this.QueryYear));
            this.JS += Benefit.Tools.ChartAtManager.ChartManager.MonthAreaBenefitPic(groupDayChanges);

            DisposeInterface();
        }



        private void InitInterface(DB.DBManager db)
        {
            #region 初始化接口
            IGroups = new Service.Sys.ServiceGroups(db);
            ITradeHistory = new Service.Sys.ServiceTradeHistory(db);
            IGroupMonthWinOrLoseTick = new Service.Month.ServiceGroupMonthWinOrLoseTick(db);
            IGroupDayChange = new Service.Day.ServiceGroupDayChange(db);
            #endregion
        }
        /// <summary>
        /// 释放接口
        /// </summary>
        private void DisposeInterface()
        {
            #region 释放接口
            IGroups = null;
            ITradeHistory = null;
            IGroupMonthWinOrLoseTick = null;
            IGroupDayChange = null;
            #endregion
        }
    }
}
